#pragma once

#include "Abstraction.h"

#include "OpaqueExpression.h"

namespace uml {

Abstraction::Abstraction(const QString& umlType)
    : Dependency(umlType) {}

void Abstraction::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Dependency::fromJson(json, errorList);
    mapping_ = JsonSerializable::create<OpaqueExpression>(json.value("mapping"), errorList);

}

void Abstraction::toJson(QJsonObject& json) {
    Dependency::toJson(json);
    if (mapping_) {
        QJsonObject mapping_json;
        mapping_->toJson(mapping_json);
        json.insert("mapping", mapping_json);
    }
}

/// <summary>
/// mapping getter
/// An OpaqueExpression that states the abstraction relationship between the
/// supplier(s) and the client(s). In some cases, such as derivation, it is usually
/// formal and unidirectional; in other cases, such as trace, it is usually informal
/// and bidirectional. The mapping expression is optional and may be omitted if the
/// precise relationship between the Elements is not specified.
/// </summary>
shared_ptr<OpaqueExpression> Abstraction::mapping() const {
    return mapping_;
}

/// <summary>
/// mapping setter
/// An OpaqueExpression that states the abstraction relationship between the
/// supplier(s) and the client(s). In some cases, such as derivation, it is usually
/// formal and unidirectional; in other cases, such as trace, it is usually informal
/// and bidirectional. The mapping expression is optional and may be omitted if the
/// precise relationship between the Elements is not specified.
/// </summary>
void Abstraction::setMapping(shared_ptr<OpaqueExpression> value) {
    mapping_ = value;
}

} // namespace uml
